import { Injectable } from '@angular/core';

import { HttpClient,HttpErrorResponse } from '@angular/common/http';
import { catchError, retry } from 'rxjs/operators';

import { NgxhttpService } from '../../@core/utils/ngxhttp.service';
import { Router } from '@angular/router';
import { NbTokenService } from '@nebular/auth';
import { Observable, throwError } from 'rxjs';

export class Comprehensive {
  id: number;
  name: string;
}

@Injectable()
export class MainService extends NgxhttpService{
  configUrl = 'assets/pages/main/config.json';

  constructor(private http: HttpClient,
              tokenService: NbTokenService,
              router : Router) {
    super(tokenService, router);
  }

  queryComprehensive(): Observable<Comprehensive>{
    return this.http.get<Comprehensive>(this.configUrl)
      .pipe(
        retry(3), // retry a failed request up to 3 times
        catchError((error: HttpErrorResponse) =>
          this.handleError(error)
        ) // then handle the error
      );
  }

/*  handleError(error: HttpErrorResponse) {
    var tt = this;
    return throwError(
      'Something bad happened; please try again later.');

  }*/
}
